<?php

use yii\helpers\Html;
use yii\helpers\Url;
use yii\grid\GridView;
use yii\widgets\DetailView;
use yii\widgets\Pjax;
use dmstr\bootstrap\Tabs;
use yii\bootstrap\ActiveForm;

/**
* @var yii\web\View $this
* @var yiike\order\model\OrderStore $model
*/
$copyParams = $model->attributes;

$this->title = Yii::t('models', '订单详情');
$this->params['breadcrumbs'][] = ['label' => Yii::t('models', '订单列表'), 'url' => ['index']];
$this->params['breadcrumbs'][] = ['label' => (string)$model->id, 'url' => ['详情', 'id' => $model->id]];
$this->params['breadcrumbs'][] = '详情';
?>
<!-- flash message -->
<?php if (\Yii::$app->session->getFlash('deleteError') !== null) : ?>
        <span class="alert alert-info alert-dismissible" role="alert">
            <button type="button" class="close" data-dismiss="alert" aria-label="Close">
            <span aria-hidden="true">&times;</span></button>
            <?= \Yii::$app->session->getFlash('deleteError') ?>
        </span>
    <?php endif; ?>
<div class="box box-info giiant-crud order-store-view">
    <div class="box-header with-border">
        <div class="box-title">
            <?= $this->title ?>        </div>
    </div>

    <div class="box-body">

        <div class="clearfix crud-navigation">

            <!-- menu buttons -->
         <!--   <div class='pull-left'>
                <?= Html::a(
                '<span class="glyphicon glyphicon-pencil"></span> ' . '编辑',
                [ 'update', 'id' => $model->id],
                ['class' => 'btn btn-info']) ?>

                <?= Html::a(
                '<span class="glyphicon glyphicon-plus"></span> ' . '新增',
                ['create'],
                ['class' => 'btn btn-success']) ?>
            </div>

            <div class="pull-right">
                <?= Html::a('<span class="glyphicon glyphicon-list"></span> '
                . 'Full list', ['index'], ['class'=>'btn btn-default']) ?>
            </div>

        </div>
-->

        <?php $this->beginBlock('yiike\order\model\OrderStore'); ?>
<div class="col-lg-12">
        <div class="col-lg-6">
        <?= DetailView::widget([
        'model' => $model,
        'attributes' => [
            'trade_id',
        'order.created_at:datetime',
            [
                'label'=>'状态',
                // 'format'=>'raw',
                'attribute'=>'status',
                'value'=>function($model){
                    if($model->status==0){
                        return '代付款';
                    }else if($model->status==1){
                        return'已付款';
                    }else if($model->status==2){
                        return '已发货';
                    }else if($model->status==3){
                        return '已完成';
                    }else{
                        return '已取消';
                    }
                },
            ],
        'total',
        'quan',
        'real_pay',
        ],
        ]); ?>
        </div>


            <div class="col-lg-6">
                <?= DetailView::widget([
                    'model' => $model,
                    'attributes' => [
                        'express_name',
                        'express_no',
                        'order.name',
                        'order.mobile',
                        [
                            'label'=>'地址',
                            'attribute'=> 'area',
                        ],
                        'order.address',
                    ],
                ]); ?>
            </div>

</div>
<div class="col-lg-12" >
    <table class="table table-bordered">
        <thead>
        <tr>
            <th>商品</th>
            <th>图片</th>
            <th>价格</th>
            <th>数量</th>
            <th>券</th>
        </tr>
        </thead>
        <tbody>
        <?php foreach($goods as $k=>$v){?>
        <tr>

            <th scope="row"><?php echo $v['title'] ;?></th>
            <td><img src="<?php echo $v['logo'] ?>" class="img-circle" width="80" height="100"></td>
            <td><?php echo $v['price'] ;?></td>
            <td><?php echo $v['num'] ;?></td>
            <td><?php echo $v['quan'] ;?></td>
        </tr>
        <?php } ?>
        </tbody>
    </table>
    </div>
            <hr/>
            <?php if($model->status==1){?>
            <div class="sendform">
            <?php $form = ActiveForm::begin([
                    'id' => 'OrderStore',
                    'layout' => 'horizontal',
                    'action'=>Url::toRoute(['order-store/send','id'=>$model->id]),
                    'enableClientValidation' => true,
                    'errorSummaryCssClass' => 'error-summary alert alert-danger',
                    'fieldConfig' => [
                        'template' => "{label}\n{beginWrapper}\n{input}\n{hint}\n{error}\n{endWrapper}",
                        'horizontalCssClasses' => [
                            'label' => 'col-sm-2',
                            #'offset' => 'col-sm-offset-4',
                            'wrapper' => 'col-sm-8',
                            'error' => '',
                            'hint' => '',
                        ],
                    ],
                ]
            );
            ?>
                <p>
                    <?= $form->field($model, 'id')->hiddenInput()?>
                    <?= $form->field($model, 'express_code')->dropDownList($express)?>
                    <?= $form->field($model, 'express_no')->textInput()->label('快递单号') ?>
                </p>
                <hr/>
                <?php echo $form->errorSummary($model); ?>
                <div class="text-center">
                <?= Html::submitButton(
                    '<span class="glyphicon glyphicon-check"></span> ' .
                    ($model->isNewRecord ? '发货' : '发货'),
                    [
                        'id' => 'save-' . $model->formName(),
                        'class' => 'btn btn-success '
                    ]
                );
                ?>
                    </div>

                <?php ActiveForm::end(); ?>
                </div>
            <?php } ?>
            <div class="col-sm-12">
                <?php if($model->status==2){ ?>
                    <div class="text-center">
                        <button class="btn btn-info get_express  text-center ">查询物流</button>
                    </div>
                <?php } ?>
            </div>

        <?php $this->endBlock(); ?>


        <?= Tabs::widget(
                     [
                         'id' => 'relation-tabs',
                         'encodeLabels' => false,
                         'items' => [
     [
        'label'   => '<b class=""># '.Html::encode($model->id).'</b>',
        'content' => $this->blocks['yiike\order\model\OrderStore'],
        'active'  => true,
    ],
 ]
                     ]
        );
        ?>    </div>

</div>

    <?php $this->beginBlock('express') ?>
    //跳转快递100查询
    $('.get_express').click(function(){
    var express_id = $("#express_id").val();
    var express_no = $("#express_no").text();
    var url = 'https://www.kuaidi100.com/chaxun?com='+express_id+'&nu='+express_no;
    window.open(url);
    });

    <?php $this->endBlock() ?>
    <?php $this->registerJs($this->blocks['express']); ?>


